<?php
// Copyright 2019 Hackware SpA <human@hackware.cl>
// "Hackware Web Services Core" is released under the MIT License terms.

namespace Hawese\Core\Exceptions;

use RuntimeException;

class ModelObjectNotFoundException extends RuntimeException
{
    private $detail;

    /**
     * @param string $model class name
     * @param string|array $keys attributes compared
     * @param string $value value to compare
     */
    public function __construct(string $model, $keys, $value)
    {
        if (!is_array($keys)) {
            $keys = [$keys];
        }

        parent::__construct(
            sprintf( // message
                "%s %s %s could not be found",
                substr(strrchr($model, '\\'), 1),
                implode(' or ', $keys),
                htmlspecialchars($value)
            ),
            3 // code
        );

        $this->detail = [
            'model' => $model,
            'keys' => $keys,
            'value' => $value
        ];
    }

    public function getDetail()
    {
        return $this->detail;
    }
}
